<template>
  <div class="contain">
    <div class="contain-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>医生分类管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="contain-body">
      <div class="body-header">
        <el-form :inline="true" size="mini">
          <el-form-item label="医生姓名">
            <el-input placeholder="请输入医生姓名" v-model="page.realName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getClassifiedManagement">查 询</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="reset">刷 新</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="body-table">
        <el-table
            :data="tableData"
            style="width: 100%">
          <el-table-column
              type="index"
              label="序号"
              width="50px"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="realName"
              label="医生名称"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="sex"
              label="性别"
              align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.sex === 1 ? '男' : '女' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="age"
              label="年龄"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="idCard"
              label="身份证号"
              show-overflow-tooltip
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="connectionPhone"
              label="联系电话"
              show-overflow-tooltip
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="hospital"
              show-overflow-tooltip
              label="就职医院"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="administrativeOffice"
              label="就职科室"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="occupationTitle"
              label="职称"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="hospitalLevel"
              label="医院等级"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="workAddr"
              label="工作地址"
              show-overflow-tooltip
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="doctorIntroduction"
              label="医生介绍"
              show-overflow-tooltip
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="personalExpertise"
              label="专业擅长"
              show-overflow-tooltip
              align="center"
          >
          </el-table-column>
          <el-table-column
              label="医师执照"
              align="center"
          >
            <template slot-scope="scope">
              <el-image
                  style="width: 50px; height: 30px"
                  :src="scope.row.doctorLicenceUrl"
                  fit="contain"></el-image>
            </template>
          </el-table-column>

          <el-table-column
              label="挂号费"
              align="center"
          >
            <template slot-scope="scope">
              <el-input size="mini" @blur="changeConsultExpense(scope.row)" oninput="value=value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')"
                        v-model="scope.row.consultExpense"></el-input>
            </template>
          </el-table-column>

          <el-table-column
              label="分类"
              align="center"
              width="250px"
          >
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.physicianRank" size="mini" @change="changeType(scope.row)">
                <el-radio :label="1">普通门诊</el-radio>
                <el-radio :label="2">专家门诊</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>

        </el-table>
      </div>
      <div class="body-page">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.pageIndex"
            :page-sizes="[10, 15, 20, 25]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      page: {
        pageIndex: 1,
        pageSize: 10,
        realName: null
      },
      total: 0
    }
  },
  created() {
    this.getClassifiedManagement()
  },
  methods: {
    changeConsultExpense(obj) {
      if (obj.consultExpense<0){
        this.getClassifiedManagement()
        return this.$message.warning('请输入有效挂号费')
      }
      let o = {
        id: obj.id,
        consultExpense: obj.consultExpense
      }
      this.axios.post('/admin-doctor/changeConsultExpense', o).then(res => {
        if (res.data.code === 200) {
          this.getClassifiedManagement()
          this.$message.success(res.data.message)
        } else {
          this.getClassifiedManagement()
        }
      })
    },
    reset() {
      this.page.realName = null
      this.page.pageSize = 10
      this.page.pageIndex = 1
      this.getClassifiedManagement()
    },
    changeType(e) {
      this.axios.post('/admin-doctor/changePhysicianRank?doctorId=' + e.id + "&physicianRank=" + e.physicianRank).then(res => {
        if (res.data.code === 200) {
          this.getClassifiedManagement()
          this.$message.success(res.data.message)
        }
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getClassifiedManagement()
    },
    handleCurrentChange(val) {
      this.page.pageIndex = val
      this.getClassifiedManagement()
    },
    getClassifiedManagement() {
      this.axios.post('/admin-doctor/getClassifiedManagement', this.page).then(res => {
        this.tableData = res.data.data.data
        this.total = res.data.data.total
      })
    }
  },
}
</script>

<style scoped lang="less">
.contain {
  width: 100%;
  height: 100%;

  .contain-header {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
  }

  .contain-body {
    width: 100%;
    height: calc(100% - 50px);
    background-color: #fff;
    padding: 1%;
    box-sizing: border-box;

    .body-header {
      width: 100%;
      height: 50px;
    }

    .body-table {
      width: 100%;
      height: calc(100% - 120px);
    }

    .body-page {
      width: 100%;
      height: 70px;
      display: flex;
      align-items: center;
    }
  }
}
</style>
